package com.whc.common.design.handle.type;

import com.whc.common.Constant;
import com.whc.vo.GeneralColumn;
import com.whc.vo.Table;
import javafx.scene.control.Tab;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

/**
 * @author wang-hai-cheng
 * @since 2022/1/1 20:03
 */
public class DetailChain extends TypeChain {

    @Override
    public Object handler(Map<String, Object> body) {
        if (!Constant.OP_TYPE.DETAIL.equals(body.get(Constant.VARIABLE_NAME.TYPE))) {
            return handle.handler(body);
        }
        AtomicReference<Table> table = new AtomicReference<>();
        body.forEach((k, v) -> {
            if (!v.equals("detail")) {
                table.set(new Table(k, new ArrayList<>()));
                table.get().getColumns().add(new GeneralColumn("id", v));
            }
        });
        return commonMapper.detailById(table.get());
    }
}